package demo01_basicGrammer

object Demo05_function_lambda {

  //1.首类函数：函数不光可以正常的定义和使用，而且函数也可以当做数据类型
  def function_oneArg(arg:String) = {
    println(s"arg:${arg}")
  }

  def function_twoArgs(arg1: String, arg2: Int): Int = {
    println(s"arg1:${arg1},arg2:${arg2}")
    111
  }

  //2.柯里化 在参数传递的过程中，想要固定某个参数值，只传递其他参数的过程（不包括默认值参数的情况）
  def function_currying(size:Int)(style:String)={
    println(s"${size}号鞋。样式是${style}")
  }


  def main(args: Array[String]): Unit = {
    val num: Int = 100
    val fun1: String => Unit = function_oneArg
    val fun11 = function_oneArg _
    val fun2: (String,Int) => Int = function_twoArgs
    val fun21 = function_twoArgs _

    fun21("tom",20)

    val shoes_41 = function_currying(41) _
    val shoes_42 = function_currying(42) _
    val shoes_43 = function_currying(43) _
    val shoes_44 = function_currying(44) _

    shoes_43("red")

    //3.scala中匿名函数
    val fun3 = (arg1: String, arg2: Int,arg3:Double) => println(s"arg1:${arg1},arg2:${arg2},arg3:${arg3}")
    fun3("tom",20,3.14)
  }

}
